#region

using System;
using System.ComponentModel.DataAnnotations;
using ThuySan.Bussiness;

#endregion

namespace ThuySan.Models
{
    [Serializable]
    public partial class PropertyModel
    {
        #region Constructor

        public PropertyModel()
        {
        }

        public PropertyModel(Property value)
        {
            PropertyId = value.PropertyId;
            Name = value.Name;
            GroupName = value.GroupName;
            IsBit = value.IsBit ?? false;
            IsNumber = value.IsNumber ?? false;
            Priority = value.Priority;
        }

        #endregion

        #region Fields

        private String _GroupName;

        private bool _IsBit;

        private bool _IsNumber;

        private String _Name;

        private Int32? _Priority;

        private Int32 _PropertyId;

        #endregion

        #region Properties

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32 PropertyId
        {
            get { return _PropertyId; }
            set { _PropertyId = value; }
        }

        //[NotChanged]
        [Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(255, ErrorMessage = "Value must be under 255 characters")]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String GroupName
        {
            get { return _GroupName; }
            set { _GroupName = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Boolean IsBit
        {
            get { return _IsBit; }
            set { _IsBit = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Boolean IsNumber
        {
            get { return _IsNumber; }
            set { _IsNumber = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32? Priority
        {
            get { return _Priority; }
            set { _Priority = value; }
        }

        #endregion

        #region Operators

        public void Update(Property value)
        {
            //value.PropertyId = PropertyId;
            value.Name = Name;
            value.GroupName = GroupName;
            value.IsBit = IsBit;
            value.IsNumber = IsNumber;
            value.Priority = Priority;
        }

        public static implicit operator PropertyModel(Property obj)
        {
            return new PropertyModel(obj);
        }

        public static implicit operator Property(PropertyModel obj)
        {
            Property value = new Property();
            obj.Update(value);
            return value;
        }

        #endregion
    }
}
